const BASE_URL = 'http://192.168.12.95:8080'
export const myReq = (options) => {
	return new Promise((resolve, reject) => {
		// console.log('api',options)
		uni.request({
			url: BASE_URL + options.url,
			method: options.method || 'GET',
			data: options.data || {},
			header: {
				"token": uni.getStorageSync("authentication")
			},
			success: (res) => {
				console.log('路由中获得的res',res)
				if(res.header['token']){
					uni.setStorageSync('authentication',res.header['token']);
				}
				if (res.data.code == 401) {
					console.log("登录失败")
					uni.redirectTo({
						url: '/pages/userInfoPage/login/login?flag=1',
						fail: (err) => {
							console.log(err)
						}
					})
					return reject(res.data)
				}
				if (res.data.code == 500) {
					uni.showToast({
						title: res.data.message,
						icon:"none"
					})
					return reject(res.data)
				}
				// 哪天返回的信息出现了问题，就回来看看。
				return resolve(res.data)
			},
			fail: (err) => {
				uni.showToast({
					title: '请求接口失败',
					image: '../../../static/Icon/global/NetError.png'
				})
				return reject(err)
			}
		})
	})
}
